using System.Collections.Generic;
using System.Runtime.Remoting.Messaging;
using Bingo.API.LocalDB;
using Bingo.LocalDB;
using Bingo.LocalDB.Entity;
using CatLib;

namespace Bingo.Facades
{
    public class LocalDB : Facade<ILocalDB>
    {
        public static void Load()
        {
            Instance.Load();
        }

        /// <summary>
        /// 删除数据库，IBoxDB中没有直接删除一个表的接口，所以这个方法显得格外亲切~
        /// 注意：删除数据库之前要关闭该数据库
        /// </summary>
        /// <param name="address">数据库地址</param>
        public void DeleteDataBase(int address)
        {
            Instance.DeleteDataBase(address);
        }

        /// <summary>
        /// 存储一个列表的数据
        /// </summary>
        /// <param name="tableName">向哪个表存数据</param>
        /// <param name="data">要存储的数据集合</param>
        public static void Save(string tableName, List<BaseObject> data)
        {
            Instance.Save(tableName, data);
        }

        /// <summary>
        /// 存储一个对象的数据
        /// </summary>
        /// <param name="tableName">向哪个表存数据</param>
        /// <param name="ob">数据</param>
        public static void Save(string tableName, BaseObject ob)
        {
            Instance.Save(tableName, ob);
        }

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="QL">QL语句</param>
        /// <param name="param">QL参数</param>
        /// <returns></returns>
        public static List<BaseObject> Get(string QL, string param)
        {
            return Instance.Get(QL, param);
        }

        public static List<BaseObject> GetAll(string QL, string param)
        {
            return Instance.GetAll(QL, param);
        }

        public static BaseObject GetById(string id)
        {
            return Instance.GetById(id);
        }

        public static void Save(string key, object value)
        {
            Instance.Save(key, value);
        }

        public static K Get<K>(string key) where K : new()
        {
            return Instance.Get<K>(key);
        }

        public static K Get<K>(string key, K @default) where K : new()
        {
            return Instance.Get<K>(key, @default);
        }

        public static List<BaseObject> GetByType(string type)
        {
            return Instance.GetByType(type);
        }

        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="data"></param>
        /// <typeparam name="T"></typeparam>
        public static void Insert<T>(T data) where T : BaseEntity
        {
            Instance.Insert(data);
        }

        public static void Insert<T>(List<T> list) where T : BaseEntity
        {
            Instance.Insert(list);
        }

        public static void Update<T>(T data) where T : BaseEntity
        {
            Instance.Update(data);
        }

        public static void Delete<T>(long Id) where T : BaseEntity
        {
            Instance.Delete<T>(Id);
        }

        public static List<T> GetAll<T>() where T : BaseEntity, new()
        {
            return Instance.GetAll<T>();
        }

        public static T GetById<T>(long Id) where T : BaseEntity, new()
        {
            return Instance.GetById<T>(Id);
        }

        public static T GetByParam<T>(string key, object value) where T : BaseEntity, new()
        {
            return Instance.GetByParam<T>(key, value);
        }

        public static bool Delete(string id)
        {
            return Instance.Delete(id);
        }

        public static bool DeleteAll<T>() where T : BaseEntity
        {
            return Instance.DeleteAll<T>();
        }
    }
}